package com.lagou.zxy.dao;

import com.lagou.zxy.entity.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;

/**
 * @program: stage-4-module-2
 * @description:
 * @author: zhangxiaoyang
 * @date: 2020-11-02 14:23
 **/
public interface OrderDAO extends JpaRepository<Order, Long> {

    @Transactional
    @Modifying
    @Query(nativeQuery = true, value = "insert into\n" +
            "        c_order " +
            "        (company_id, create_time, is_del, position_id, publish_user_id, resume_type, status, update_time, user_id, id) \n" +
            "    values\n" +
            "        (:#{#order.companyId},:#{#order.createTime},:#{#order.del},:#{#order.positionId},:#{#order.publishUserId},:#{#order.resumeType},:#{#order.status},:#{#order.updateTime},:#{#order.userId},:#{#order.id})")
    Integer add(@Param("order") Order order);

    @Query(value = "select * from c_order where id=?1", nativeQuery = true)
    Order getById(@Param("id") Long id);
}
